package com.star;

import org.apache.catalina.Context;
import org.apache.catalina.connector.Connector;
import org.apache.tomcat.util.descriptor.web.SecurityCollection;
import org.apache.tomcat.util.descriptor.web.SecurityConstraint;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory;
import org.springframework.context.annotation.Bean;

@SpringBootApplication
public class MyblogApplication{

    public static void main(String[] args) {
        SpringApplication.run(MyblogApplication.class, args);
    }

//    @Bean
//    public Connector connector() {
//        Connector connector = new Connector("org.apache.coyote.http11.Http11NioProtocol");
//        /*
//         * 当我们访问http://localhost:8080的时候系统会自动重定向到https://localhost:8033这个地址上
//         * HTTP端口为：80
//         * HTTPS端口为：443
//         * 假如我们配置了域名，那么http://www.test.com和https://www.test.com都可实现访问
//         */
//        connector.setPort(80);
//        connector.setRedirectPort(443);
//        connector.setScheme("http");
//        connector.setSecure(false);
//        return connector;
//    }
//    @Bean
//    public TomcatServletWebServerFactory tomcatServletWebServerFactory() {
//        TomcatServletWebServerFactory tomcat = new TomcatServletWebServerFactory() {
//            @Override
//            protected void postProcessContext(Context context) {
//                SecurityConstraint securityConstraint = new SecurityConstraint();
//                securityConstraint.setUserConstraint("CONFIDENTIAL");
//                SecurityCollection collection = new SecurityCollection();
//                collection.addPattern("/*");
//                securityConstraint.addCollection(collection);
//                context.addConstraint(securityConstraint);
//            }
//        };
//        tomcat.addAdditionalTomcatConnectors(connector());
//        return tomcat;
//    }

}
